package com.guigu.qingcheng.service.Impl;

import com.guigu.qingcheng.dao.LocalMapper;
import com.guigu.qingcheng.service.LocalService;
import com.qingcheng.pojo.goods.Category;
import com.qingcheng.pojo.goods.Spu;
import com.qingcheng.pojo.goods.TbCategory;
import com.qingcheng.pojo.goods.TbSpu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LocalServiceimpl implements LocalService {

    @Autowired
    private LocalMapper localMapper;

    //  首页菜单家用电器显示
    @Override
    public HashMap<TbCategory, List<TbSpu>> appliances(String parent_id) {
        System.out.println("进入");
        // 查询前七天的热门电器
        LocalDate date1=LocalDate.now().minusDays(7);
        LocalDate date2=LocalDate.now();
        List<TbSpu> spus = null;

        List<TbCategory> categories=localMapper.appliances(parent_id,date1,date2);
        if(categories.size()==0){
            categories = localMapper.Nullappliances(parent_id);
        }
        HashMap map=new HashMap();
        for (TbCategory category : categories) {
            spus = localMapper.NullHotGoods(category.getId());
            map.put(category,spus);
        }
        return map;
    }

}
